﻿@using Eksponent.CropUp
@using Lu.Blog.Domain.Model.DocumentType
@using Lu.Blog.Domain.Utils
@using Vega.USiteBuilder
@inherits Vega.USiteBuilder.UmbracoTemplatePageBase<Lu.Blog.Domain.Model.DocumentType.Author>

@{
    ViewBag.BodyClass = "blog";
    Layout = "_Master.cshtml";

    var page = ContentHelper.GetByNodeId<Author>(Model.Content.Id);
}
<!-- MAIN -->
<div id="main">
    <div class="wrapper cf">
        <!-- portfolio content-->
        <div id="portfolio-content" class="cf">
            <!-- project box -->
            <div id="project-box" class="cf">
                <!-- slider -->
                <div class="project-slider">
                    @{
                        var slidersList = new List<ContentPage>();
                        
                        var contentPages = BlogContentHelper.GetAllPost().Where(p => p.NodeTypeAlias == "ContentPage").OrderBy(p=>p.CreateDate).ToList();
                        foreach (var contentPage in contentPages)
                        {
                            var contentPageObj = ContentHelper.GetByNodeId<ContentPage>(contentPage.Id);
                            var isAuthor = XmlNodePickerHelper.GetContentNodesFromPicker(contentPageObj.Author).Any(a => a.Id == Model.Content.Id);
                            if (contentPageObj.IsSlider && isAuthor)
                            {
                                slidersList.Add(contentPageObj);
                            }
                        }
                    }
                    @if (slidersList.Any())
                    {
                        <div class="flexslider">
                            <ul class="slides">
                                @foreach (var item in slidersList)
                                {
                                    var image = XmlNodePickerHelper.GetImagesFromPicker(item.PreviewImage).First();
                                    <li>
                                        <img src="@CropUp.GetUrl(image == null ? "" : image.NiceUrl, new ImageSizeArguments{CropAlias = "homeSlider"})" alt="@item.Name" />
                                    </li>
                                }
                            </ul>
                        </div>
                    }
                </div>
                <!-- ENDS slider -->

                <div class="info">
                    <p><strong>Prénom </strong>@page.AuthorFirstName</p>
                    <p><strong>Nom </strong>@page.AuthorLastName</p>
                    <p><strong>Date de naissance </strong>@page.AuthorBirthdate.ToString("d MMMM")</p>
                </div>
	        		
                <!-- entry-content -->
                <div class="entry-content">
	        		
                    <h2 class="heading">@page.Username</h2>
	        			
                    <div class="multicolumn">
                        @Html.Raw(page.AuthorAboutText)
                    </div>
                </div>
                <!-- ENDS entry content -->
	        		
            </div>
            <!-- ENDS project box -->
					
            @{
                var relatedPosts = new List<ContentPage>();
            }
            @foreach (var contentPage in contentPages)
            {
                var contentPageObj = ContentHelper.GetByNodeId<ContentPage>(contentPage.Id);
                var isAuthor = XmlNodePickerHelper.GetContentNodesFromPicker(contentPageObj.Author).Any(a => a.Id == Model.Content.Id);
                if (isAuthor)
                {
                    relatedPosts.Add(contentPageObj);
                    if (relatedPosts.Count >= page.AuthorPostCount)
                    {
                        break;
                    }
                }
            }
            
            @if (relatedPosts.Any())
            {
                <!-- related -->
                <div class="related-projects">
                    <h4 class="related-heading">Derniers posts</h4>
                    <div class="related-list cf">
                        @foreach (var post in relatedPosts)
                        {
                            var image = XmlNodePickerHelper.GetImagesFromPicker(post.PreviewImage).First();
                            <figure>
                                <a href="@post.NiceUrl" class="thumb"><img src="@CropUp.GetUrl(image == null ? "" : image.NiceUrl, new ImageSizeArguments{CropAlias = "relatedPost"})" alt="@post.Name" /></a>
                                <a href="@post.NiceUrl" class="heading">@post.Name</a>
                            </figure>
                        }
                    </div>
                </div>
                <!-- ENDS related -->
            }
        </div>
        <!-- ENDS portfolio content-->
    </div><!-- ENDS WRAPPER -->
</div>
<!-- ENDS MAIN -->

@functions
{
}